let ClickCellNode = require('ClickCellNode');
let dragons = require('dragons');
let eventsMgr = require('eventsMgr');
let consts = require('consts');
cc.Class({
    extends: ClickCellNode,

    properties: {
        boneNodes:[cc.Node],
        idle:'idle',
        selected:'select',

        maxSelectCount:{
            default:1,
            tooltip:'最大选中次数，一般选择一次',
        },
    },

    // LIFE-CYCLE CALLBACKS:


    start () {
        // function(node,name,playTime,complete)
        let self = this;
        self._super();
        self.curSelectCount = 0;
        self.playAct(self.idle,0);
    },
    isSelected(){
        let self = this;
        if (!self.curSelectCount){
            self.curSelectCount = 0;
        }
        return self.curSelectCount >= self.maxSelectCount;
    },
    onTouch(){
        let self = this;
        if (self.clickEnable && self.curSelectCount<self.maxSelectCount){
            self.curSelectCount++;
            self.playAct(self.selected,0);
            eventsMgr.emit(consts.EVENTS.CLICK, {target:self});
        }
    },
    playAct(act,playTime){
        let self = this;
        for (let i=0;i<self.boneNodes.length;i++){
            dragons.playAnimation(self.boneNodes[i],act,playTime);
        }
    }
    // update (dt) {},
});
